<template>
  <div class="app-container">
    <uc-table url="/sys/post/getPostPage" name="岗位管理" ref="buildingTable" pageable table-border :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-input type="text" v-model="searchForm.postName" placeholder="请输入岗位名称" clearable @clear="clearInput()"></el-input>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="postName" label="岗位名称" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="postCode" label="岗位编码" align="left" :show-overflow-tooltip="true"></el-table-column>

        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInPost} from "@/api/post";
import {getInEnterpriseList} from "@/api/enterprise";
import {getPostList} from "@/api/post";


export default {
  name: "postList",
  components: {UcTable},
  data(){
    return{
      searchForm:{
        deleted:false,
      },
      deleteLoading:false,
      postList:[]
    }
  },
  created() {
    // this.getPostList()
  },
  methods:{
    handleSearch(){
      this.$refs.buildingTable.getTableData(1)
    },
    handleAdd(){
      this.$router.push("/sys/post/edit")         //新增按钮     修改路径??
    },
    handleEdit(val){
      this.$router.push("/sys/post/edit?id="+val.id)          //编辑按钮     重新加载eidt，自动填充数据，然后修改
    },
    clearInput(){
      //清除输入框
      this.searchForm.postName = null
      this.handleSearch()
    },
    clearInput1(){
      //清除输入框
      this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    handleDelete(val){
      this.$confirm('您确定要执行删除'+val.postName+'这个岗位吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        deleteInPost(val).then(res=>{
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除岗位成功"
          })
          this.handleSearch()
        }).catch(res=>{
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getInEnterpriseDominantList(){
      getPostList({deleted:false}).then(res=>{
        this.postList = res.data
      }).catch(error=>{

      })
    },
  },

}
</script>

<style scoped>

</style>